#pragma once

#include "InteractionConstraint.h"

#include "ValueSpecification.h"

namespace uml {

InteractionConstraint::InteractionConstraint(const QString& umlType)
    : Constraint(umlType) {}

void InteractionConstraint::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Constraint::fromJson(json, errorList);
    maxint_ = JsonSerializable::create<ValueSpecification>(json.value("maxint"), errorList);

    minint_ = JsonSerializable::create<ValueSpecification>(json.value("minint"), errorList);

}

void InteractionConstraint::toJson(QJsonObject& json) {
    Constraint::toJson(json);
    if (maxint_) {
        QJsonObject maxint_json;
        maxint_->toJson(maxint_json);
        json.insert("maxint", maxint_json);
    }
    if (minint_) {
        QJsonObject minint_json;
        minint_->toJson(minint_json);
        json.insert("minint", minint_json);
    }
}

/// <summary>
/// maxint getter
/// The maximum number of iterations of a loop
/// </summary>
shared_ptr<ValueSpecification> InteractionConstraint::maxint() const {
    return maxint_;
}

/// <summary>
/// maxint setter
/// The maximum number of iterations of a loop
/// </summary>
void InteractionConstraint::setMaxint(shared_ptr<ValueSpecification> value) {
    maxint_ = value;
}

/// <summary>
/// minint getter
/// The minimum number of iterations of a loop
/// </summary>
shared_ptr<ValueSpecification> InteractionConstraint::minint() const {
    return minint_;
}

/// <summary>
/// minint setter
/// The minimum number of iterations of a loop
/// </summary>
void InteractionConstraint::setMinint(shared_ptr<ValueSpecification> value) {
    minint_ = value;
}

} // namespace uml
